package com.yksj.healthtalk.net.socket;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import sfs2x.client.core.IEventListener;
import sfs2x.client.requests.IRequest;
import sfs2x.client.requests.LogoutRequest;
import android.content.Context;
import android.content.Intent;

import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.yksj.healthtalk.entity.CustomerInfoEntity;
import com.yksj.healthtalk.entity.MessageEntity;
import com.yksj.healthtalk.services.MessagePushService;
import com.yksj.healthtalk.utils.LogUtil;
import com.yksj.healthtalk.utils.SystemUtils;
import com.yksj.healthtalk.utils.ToastUtil;

/**
 * SmartFoxClient用于发送所有的socket请求
 */
public class SmartFoxClient {
	private static final String TAG = "SmartFoxClient";
	public static final String EXTENTION_SMS_SYS_INITIALIZATION = "sms_sys_initialization";
	public static final int CONNECTION_TIMEOUT = 1000 * 15;// 连接超时
	public static final String KEY_CODE = "server_code";
	public static final String KEY_PARAME = "server_parame";
	public static final String KEY_VALUE_GROUPID = "groupid";
	public static final String KEY_VALUE_INCEPTMESSAGE = "inceptMessage";
	public static final String ROOM_NAME = "minihome";
	public static final String SYSTEM_VERSION = "system_version";
	public static final String OS_TYPE = "os_type";
	public static final String KEYWORDS = "keyWords";
	public static final String KEY_VALUE_MESSAGE="sms_req_content";
	public static final String KEY_CONTENT="content";
	/**
	 * 多美助手id
	 */
	public static final String helperId = "100000";
//	private static volatile SmartFoxClient smartFoxClient;
	
	/*private SmartFox mSmartFox;
	private boolean loginflag = false;//
	private boolean iscreate = false;
	private CustomerInfoEntity customerInfoEntity;
	private String osType = "1";
	private String osVersion;
	private String userMd5Id;
	private String userId;
	private String userName;
	private String userPas;
	private String zoneName;
	private String imei;
	private int port;
	private String ip;
	private IEventListener mEventListener;*/
//	private ConnectHandler mConnectCheck;
//	private Looper mLooper;
	/**
	 * 连接检测
	 * @author zhao
	 */
/*	private final class ConnectHandler extends Handler{
		public ConnectHandler(Looper loop){
			super(loop);
		}
		@Override
		public void handleMessage(Message msg) {
		}
	};*/
	
	private static SmartControlClient smartFoxClient;
	private static SmartFoxClient mFoxClient;
	
	static{
		mFoxClient = new SmartFoxClient();
	}
	
	public SmartFoxClient() {
		smartFoxClient = SmartControlClient.getControlClient();
//		HandlerThread handlerThread = new HandlerThread("healthtalk_connection");
//		handlerThread.start();
//		mConnectCheck = new ConnectHandler(mLooper = handlerThread.getLooper());
		/*Application context = HTalkApplication.getHTalkApplication();
		System.setProperty("java.net.preferIPv6Addresses", "false");
		this.imei = SystemUtils.getImeiId();
		if(imei == null) imei = String.valueOf(System.currentTimeMillis());
		Resources resources = context.getResources();
		String port = resources.getString(R.string.smart_port);
		this.ip = resources.getString(R.string.smart_ip);
		this.zoneName = resources.getString(R.string.smart_zone);
		this.port = Integer.valueOf(port);
		this.osVersion = SystemUtils.getAppVersionName(context);
		initSmartFox();*/
	}
	
	/**
	 * 设置smartfox基本信息
	 * @param context
	 */
	private synchronized void initSmartFox() {
		/*mSmartFox = new SmartFox(LogUtil.DEBUG);
		addEventHandler(mEventListener);*/
	}

	public CustomerInfoEntity getCustomerInfoEntity() {
		return smartFoxClient.getInfoEntity();
	}
	public void setCustomerInfoEntity(CustomerInfoEntity customerInfoEntity) {
		smartFoxClient.setCustomerInfoEntity(customerInfoEntity);
//		this.customerInfoEntity = customerInfoEntity;
	}
/*	public boolean isLoginflag() {
		return loginflag;
	}

	public void setLoginflag(boolean loginflag) {
		this.loginflag = loginflag;
	}*/

	/*public boolean isIscreate() {
		return iscreate;
	}

	public void setIscreate(boolean iscreate) {
		this.iscreate = iscreate;
	}*/

	public String getUserMd5Id() {
		return smartFoxClient.getUserMd5Id();
	}

	public void setUserMd5Id(String userid) {
		//this.userMd5Id = MD5Utils.generateMD5Str(userid);
	}

	public String getUserId() {
		return smartFoxClient.getUserId();
	}

	public void setUserId(String userId) {
		//this.userId = userId;
	}


	public String getUserName() {
		return smartFoxClient.getInfoEntity().getUsername();
	}

	public void setUserName(String userName) {
		//this.userName = userName;
	}


	public String getUserPas() {
		return smartFoxClient.getPassword();
	}

	public void setUserPas(String userPas) {
		/*if(userPas.length() <= 12){
			this.userPas = MD5Utils.getMD5(userPas);
		}else{
			this.userPas = userPas;
		}*/
	}


	public String getZoneName() {
		return null;
	}


	public void setZoneName(String zoneName) {
		//this.zoneName = zoneName;
	}


	public String getImei() {
		return null;
	}


	public void setImei(String imei) {
		//this.imei = imei;
	}


	public int getPort() {
		return 0;
	}


	public void setPort(int port) {
		//this.port = port;
	}


	public String getIp() {
		return "";
	}


	public void setIp(String ip) {
//		this.ip = ip;
	}
	
	public void sendJoinRoom(){
		//mSmartFox.send(new JoinRoomRequest(mSmartFox.getRoomByName(ROOM_NAME)));
	}
	
	public static SmartFoxClient getSmartFoxClient() {
		return mFoxClient;
	}
	
	public boolean isConnected(){
		return mFoxClient.isConnected();
	}
	
	/**
	 * 加载客户资料
	 */
	public static void sendLoadUserInfo(){
		sendStrRequest(SmartFoxClient.RequestCode.CUSTOMER_INFO_REQ, null);
	}
	
	/**
	 * 修改个人资料
	 * @param code
	 * @param str
	 */
	public static void changePersonalInfo(String str){
		sendStrRequest(RequestCode.CODE_CHANGE_PERSONALINFO,str);
	}
	
	/**
	 * 发送请求
	 * @param code 请求码
	 * @param str  json参数
	 */
	public static void sendStrRequest(int code,String str){
		ISFSObject isfsObject = new SFSObject();
		isfsObject.putInt(KEY_CODE,code);
		if(str != null)isfsObject.putUtfString(KEY_PARAME, str);
		smartFoxClient.doSendExtentionReq(isfsObject);
	}
	
	/**
	 * 发送请求
	 * @param code 请求码
	 * @param str  json参数
	 */
	public static void sendStrRequest(int code,String str,String content){
		ISFSObject isfsObject = new SFSObject();
		isfsObject.putInt(KEY_CODE,code);
		if(str != null){
			isfsObject.putUtfString(KEY_PARAME, str);
			isfsObject.putUtfString("COMPLAINT_CONTENT", content);
		}
		smartFoxClient.doSendExtentionReq(isfsObject);
	}
	
	/**
	 * 发送保持连接请求
	 */
	public static void sendKeepConnect(){
		ISFSObject isfsObject = new SFSObject();
		isfsObject.putInt(KEY_CODE,RequestCode.KEEP_CONECTION_REQ);
		smartFoxClient.doSendExtentionReq(isfsObject);
	}
	
	/**
	 * 改变当前为登出状态
	 */
	public synchronized static void changeLogOut(){
		//isLogined = false;
	}
	
	private synchronized void doSendExtentionReq(ISFSObject sfsObject) {
		/*sfsObject.putUtfString(SYSTEM_VERSION,osVersion);
		sfsObject.putUtfString(OS_TYPE,osType);
		doSend(new ExtensionRequest(EXTENTION_SMS_SYS_INITIALIZATION, sfsObject,mSmartFox.getLastJoinedRoom()));*/
	}																																																																													

	private void doSend(IRequest iRequest) {
		/*synchronized (mSmartFox) {
			if (mSmartFox.isConnected())
				mSmartFox.send(iRequest);
		}*/
	}
	
	/**
	 * 发送登出请求
	 */
	public void doSendLogOut() {
		doSend(new LogoutRequest());
	}

	/**
	 * 发送连接服务器请求
	 */
	public synchronized void doConnecion() {
		/*new Thread() {
			public void run() {
				synchronized (mSmartFox) {
						try{
							initSmartFox();
							mSmartFox.connect(ip, port);
						}catch(Exception e){
							e.printStackTrace();
						}
					}
				}
		}.start();*/
	}
	
	public void doSendLogin(){
		doConnecion();
	}

	/**
	 * 注销
	 * @param str
	 */
	public static void ifServerParame(String str){
		sendStrRequest(RequestCode.SERVER_PARAME,str);
	}
	
	/**
	 * 获取在线成员
	 * @param str groupid
	 */
	public static void getChattingOnlineFriends(String str){
		sendStrRequest(RequestCode.CHATTING_ONLINE_FRIEND,str);
	}
	/**
	 * 发送登陆
	 * @param name
	 * @param pas
	 */
	private void doSendLogin(String name,String pas) {
		this.setUserName(name);
		this.setUserPas(pas);
//		doSendReqLogin();
	}

	
	/**
	 * 通讯录好友能找到我
	 * @param str
	 */
	public static void ifCanFindMe(String str){
		sendStrRequest(RequestCode.CODE_FIND_ME,str);
	}
	
	
	
	/**
	 * 用户加入房间
	 */
	public static void sendJoinRoomReq(){
		smartFoxClient.sendJoinRoom();
	}

	public static boolean checkConnection(Context context){
		if(!SystemUtils.isNetWorkValid(context)){
			ToastUtil.showGetWayError(context);
			return false;
		}
		if(SystemUtils.isNetWorkValid(context)){
			ToastUtil.showLoginOutError(context);
			context.sendBroadcast(new Intent(MessagePushService.ACTION_CONNECTION_LOST));
			return false;
		}
		return true;
	}
	
	/**
	 * 加入聊天室
	 */
	public static void sendJoinGroupChat(String id){
		sendStrRequest(RequestCode.JOIN_GROUP_CHAT,id);
	}
	
	/**
	 * 初始化smartfox对象
	 * @param context
	 * @return
	 */
	/*public synchronized static SmartFoxClient initSmartFoxClient() {
		if (smartFoxClient == null) {
			smartFoxClient = new SmartFoxClient();
		}
		return smartFoxClient;
	}*/

	/**
	 * 销毁smartfox对象
	 */
	/*public synchronized static void destorySmartFox() {
		if (smartFoxClient != null) {
			smartFoxClient.destory();
		}
	}*/
	
	/**
	 * 发送连接请求
	 */
	/*public synchronized static void sendConnection(){
		if (smartFoxClient != null) {
			smartFoxClient.doConnecion();
		}
	}
	
	public static SmartFox getSmartFox(){
		if(smartFoxClient == null)return null;
		return smartFoxClient.mSmartFox;
	}*/
	
	/**
	 * 
	 * 获得登陆者的id
	 * @return
	 */
	public static String getLoginUserId(){
		return smartFoxClient.getUserId();
/*//		if(true)return "2599";
		if(smartFoxClient == null || smartFoxClient.customerInfoEntity == null)return null;
		return smartFoxClient.customerInfoEntity.getId();*/
	}
	
	/**
	 * 
	 * 登陆用户信息
	 * @return
	 * 
	 */
	public static CustomerInfoEntity getLoginUserInfo(){
		return smartFoxClient.getInfoEntity();
	}
	
	/**
	 * 
	 * 当前是否已经连接
	 * @return
	 */
	/*public static boolean isConnected(){
		if(smartFoxClient == null)return false;
		return SmartFoxClient.getSmartFox().isConnected();
	}*/
	
	/**
	 * 举报
	 * @param str
	 */
	public static void report(String str,String content){
		sendStrRequest(RequestCode.CODE_REPORT,str,content);
	}
	
	/**
	 * 当前是否正在连接中
	 * @return
	 */
	/*public static boolean isConnecting(){
		if(smartFoxClient == null)return false;
		return SmartFoxClient.getSmartFox().isConnecting();
	}*/
	/**
	 * 
	* @Title: sendIsInceptMessage 
	* @Description: 是否接受群消息
	* @param @param groupid
	* @param @param inceptMessage    
	* @return void    
	* @throws
	 */
	public static void sendIsInceptMessage(String groupid,String inceptMessage){
		sendIsInceptMessage(RequestCode.CODE_INCEPTMESSAGE,groupid,inceptMessage); 
	}
	
	/**
	 * 
	* @Title: sendIsInceptMessage 
	* @Description: 是否接受群消息
	* @param @param code
	* @param @param groupid
	* @param @param inceptMessage    
	* @return void    
	* @throws
	 */
	public static void sendIsInceptMessage(int code,String groupid,String inceptMessage ){
		ISFSObject isfsObject = new SFSObject();
		isfsObject.putInt(KEY_CODE,code);
		if(groupid != null)isfsObject.putUtfString(KEY_VALUE_GROUPID, groupid);
		if(inceptMessage != null)isfsObject.putUtfString(KEY_VALUE_INCEPTMESSAGE, inceptMessage);
		smartFoxClient.doSendExtentionReq(isfsObject);
	}
	
	/**
	 * 发送保持连接请求
	 */
	public static void sendKeepConnectReq() {
		if(smartFoxClient != null){
			ISFSObject isfsObject = new SFSObject();
			isfsObject.putInt(KEY_CODE, RequestCode.KEEP_CONECTION_REQ);
			smartFoxClient.doSendExtentionReq(isfsObject);
			LogUtil.d(TAG,"smartfox keepconnect sended");
		}
	}
	
	/**
	 * 发送登陆请求
	 */
	public static void sendLoginReq(String name, String pas) {
		/*smartFoxClient.doSendLogin(name, pas);*/
		smartFoxClient.login();
	}
	
	/**
	 * 发送重新登陆请求
	 */
	public static void sendRetLoginReq() {
		smartFoxClient.login();
	}
	
	public static void sendLogoutReq(){
		smartFoxClient.logout();
	}
	
	/**
	 * 发送聊天信息
	 */
	public static void sendChatMessage(String mesgId,String tagertId,boolean isGroupMessage,int type,float duration,String content,String voiceLength,String fileName,String dataHolder){
		ISFSObject isfsObject = new SFSObject();
		if(isGroupMessage){
			isfsObject.putInt(KEY_CODE,9045);
		}else{
			if(SmartFoxClient.helperId.equals(mesgId)){
				isfsObject.putInt(KEY_CODE,SmartFoxClient.RequestCode.CHAT_HEALPER);
			}else{
				isfsObject.putInt(KEY_CODE,9018);
			}
		}
		isfsObject.putUtfString("serverId",mesgId);//消息返回状态id,与前台id进行对应
		isfsObject.putUtfString("sms_req_content",content);
		isfsObject.putUtfString("customerId",smartFoxClient.getUserId());
		isfsObject.putInt("isGroupMessage",isGroupMessage?1:0);
		isfsObject.putUtfString("timeStamp",String.valueOf(System.currentTimeMillis()));
		isfsObject.putUtfString("sms_target_id", tagertId);
		if(fileName != null)isfsObject.putUtfString("fileName", fileName);
		if(dataHolder != null)isfsObject.putUtfString("dataHolder", dataHolder);//地图坐标
		isfsObject.putInt("type", type);
		isfsObject.putFloat("duration", duration);
		smartFoxClient.doSendExtentionReq(isfsObject);
	}
	
	/**
	 * 公开位置信息
	 * @param str
	 */
	public static void ifPublicLocation(String str){
		sendStrRequest(RequestCode.CODE_PUBLIC_LOCATION,str);
	}
	/**
	 * 推送健康贴士
	 * @param str
	 */
	public static void ifPushAttention(String str){
		sendStrRequest(RequestCode.CODE_PUSH_ATTENTION,str);
	}
	
	/**
	 * 兴趣墙图片转发
	 * 
	 * flag 放入smartfox内的标志位 话题2,好友1
	 * @param ids
	 */
	public static void sendRepeatToFriend(String flag,String ids,String picId){
		SFSObject sfsObject = new SFSObject();
		sfsObject.putInt(KEY_CODE, RequestCode.CODE_REPEAT_MESSAGE);
		sfsObject.putUtfString("sms_verifyFlag", flag);
		sfsObject.putUtfString("session", "");
		sfsObject.putUtfString("sms_stringid", ids);
		sfsObject.putUtfString("wall_pictureid", picId);
		smartFoxClient.doSendExtentionReq(sfsObject);
	}
	
	/**
	 * 兴趣墙 转发 (我的所有(沙龙 朋友))
	 * MYATTENTION 我关注的人
		ATTENTIONME 关注我的人
		MYCREATE 我创建的群
		MYATTENTIONGROUP 我关注的群
	 */
	public static void  sendRepeatToAll(String flag,String picId){
		SFSObject sfsObject = new SFSObject();
		sfsObject.putUtfString("flag", flag);
		sfsObject.putInt(KEY_CODE, RequestCode.CODE_REPEAT_PIC);
		sfsObject.putUtfString("session", "");
		sfsObject.putUtfString("wall_pictureid", picId);
		smartFoxClient.doSendExtentionReq(sfsObject);
	}
	
	
	/**
	 * 
	 * 查询禁言列表
	 * 
	 */
	public static void queryForbiddenWordsList(String chatId){
		sendStrRequest(SmartFoxClient.RequestCode.CODE_FORBIDWORDS_LIST,chatId);
	}
	
	/**
	 * 
	 * 更新禁言列表
	 * 
	 */
	public static void updateForbiddenWordsList(String groupId,Collection<String> collection){
		SFSObject sfsObject  = new SFSObject();
		sfsObject.putUtfString("groupid",groupId);
		sfsObject.putUtfStringArray(KEY_PARAME, collection);
		sfsObject.putInt(KEY_CODE,SmartFoxClient.RequestCode.CODE_UPDATE_FORBIDWORDS_LIST);
		smartFoxClient.doSendExtentionReq(sfsObject);
	}
	
	/**
	 * 服务编码
	 * @author zhao yuan
	 */
	public static class RequestCode {
		public static final int LOGIN_REQ = 1024;
		public static final int KEEP_CONECTION_REQ = 100;// 保持连接定时检测
		// 小贴士
		public static final int CODE_NEWS = 9111;
		public static final int CODE_REPORT = 9100; // 举报
		
		public static final int CODE_REPEAT_MESSAGE = 9133;//转发
		/**
		 * 聊天
		 */ 
		public static final int CHATTING_MESSAGE_REQ = 9900;
		public static final int CHATTING_INVITE_RECEIVE = 9088; // 接收群邀请消息
		public static final int CHATTING_SINGLE_MESSAGE_RECEIVE = 9019;// 接受单聊消息
		public static final int CHATTING_MESSAGE_SENDSTATE = 9018;// 消息发送状态返回
		public static final int CHATTING_GROUP_MESSAGE_RECEIVE = 9045;// 群聊接收
		public static final int CHATTING_GROUP_MESSAGE_SEND = 9045;// 群聊发送,接收
		public static final int DIALOG_CHECK_VALIDATOR_REQ = 9099;// 虚拟医生聊天关联检查话题是否存在
		public static final int DIALOG_CREATE_REQ = 9098;// 虚拟医生聊天关联话题创建话题
		public static final int CHATTING_ONLINE_FRIEND = 9142;//在线成员
		/**
		 * news
		 */
		public static final int CODE_ATTENTION = 9056; // 加载我的关注
		public static final int CODE_MY_ATTENTION_DELE = 9058;// 取消关注
		public static final int CODE_MY_ATTENTION_ADD = 9057; // 添加关注

		/**
		 * 健康友
		 */
		public static final int CUSTOMER_INFO_REQ = 9222; // 请求客户基本信息
		public static final int LOAD_FRIEND_LIST = 9001; // 加载健康友列表
		public static final int CODE_SEARCH_FRIEND = 9021; // 按条件搜索健康友
		public static final int CODE_COLLECT_FRIEND = 9024; // 1收藏或0删除好友,2加入黑名单,3移除黑名单
		public static final int CODE_PUBLIC_LOCATION = 9106; // 是否公开自己位置
		public static final int CODE_CHANGE_LOCATION = 9062; // 更改自己位置9062
		public static final int CODE_PUSH_ATTENTION = 9118;// 推送健康贴士
		public static final int SERVER_PARAME = 9125;// 注销
		public static final int CODE_INCEPTMESSAGE = 9120; // 是否接受群消息
		// 9025要改
		public static final int CODE_FIND_ME = 9025; // 通讯录好友能否找到我

		/**
		 * 个人资料
		 */
		public static final int CODE_CHANGE_PERSONALINFO = 9026; // 修改个人信息
		public static final int CODE_GET_ATTENTION = 9077; // 查询关注信息
		public static final int CODE_GET_WANTKNOW = 9081; // 查询我想了解
		public static final int CODE_CHANGE_WANTKNOW = 9080; // 更改我想了解
		public static final int CODE_CHANGE_PASSWORD = 9043; // 更改密码
		public static final int CODE_SEND_FACEBACK = 9079; // 意见反馈

		/**
		 * 聊天室
		 */
		public static final int LOAD_GROUP_LIST = 9003; // 加载聊天室列表
		public static final int SEARCH_GROUP_ATT = 9006; // 按关注搜索聊天室
		public static final int SEARCH_GROUP_NAME = 9008; // 按话题搜索聊天室
		public static final int COLLECT_GROUP = 9073; // 收藏聊天室
		public static final int COLLECT_GROUP_NOT = 9074; // 取消收藏聊天室
		public static final int GROUP_HALL = 9071; // 加载消息厅
		public static final int JOIN_GROUP_CHAT = 9090;// 加入聊天室
		public static final int EXIT_GROUP_CHAT = 9091;// 退出聊天室
		public static final int GROUP_INVITE = 9149; // 群邀请
		public static final int GROUP_ONLINE = 9047;// 当前群的在线用户
		public static final int DOCTOR_SEND_PERSON_MESSAGE=9137;//医生向用户群发
		public static final int DOCTOR_INFO_AUDIT = 9108; // 医师资格审核
		public static final int OFFLINE_DELE = 9104; // 删除离线消息
		
		/**
		 * 账号异地登录
		 */
		public static final int LOGIN_OTHERPLACE = 9105; // 账号异地登录
		public static final int CHAT_HEALPER = 9112;// 多美妹子聊天
		public static final int NOTIFY_MESSAGE = 9114;// 通知
		public static final int CODE_NOTIFY_FILTER = 9127;// 发布厅筛选
		public static final int CODE_UPDATE_FORBIDWORDS_LIST = 9126;// 禁言列表更新
		public static final int CODE_FORBIDWORDS_LIST = 9129;// 禁言列表查询
		
		
		public static final int CODE_CHARGE_STATE = 9145;//医生收费请求发送状态返回
		public static final int CODE_CHARGE = 9146;//医生收费请求
		
		public static final int CODE_PRODUCT_CHANGE = 10008;//订单变化通知
		public static final int CODE_LEAVE_WORDS = 120;//留言
		
		public static final int CODE_REPEAT_PIC =9134;  //转发 (兴趣墙 全选的)
		
	}
	
	
	/**
	 * 加载当前群在线的成员列表
	 * @param groupId 群id
	 */
	public static boolean loadChatGroupOnlineMenbers(String groupId){
		ISFSObject isfsObject = new SFSObject();
		isfsObject.putInt(KEY_CODE,SmartFoxClient.RequestCode.GROUP_ONLINE);
		isfsObject.putUtfString(KEY_PARAME,groupId);
		smartFoxClient.doSendExtentionReq(isfsObject);
		return true;
	}
	
	/**
	 * 医生向患者群发消息
	 * @return
	 */
	public static void doctorSendMessageToPersons(String message,String id){
		ISFSObject isfsObject = new SFSObject();
		isfsObject.putUtfString("PATIENT_GROUP_ID",id);
		isfsObject.putInt(KEY_CODE,SmartFoxClient.RequestCode.DOCTOR_SEND_PERSON_MESSAGE);
		isfsObject.putUtfString(KEY_VALUE_MESSAGE,message);
		isfsObject.putUtfString("session", "");
		smartFoxClient.doSendExtentionReq(isfsObject);
	}
	
	/**
	 * 群邀请
	 * @param groupId  群ID
	 * @param content  被邀请人ID
	 */
	public static boolean sendGroupInvite(Context context,String groupId,List<String> inviteId){
		ISFSObject isfsObject = new SFSObject();
		isfsObject.putInt(KEY_CODE,SmartFoxClient.RequestCode.GROUP_INVITE);
		String content = "";
		for(int i= 0; i < inviteId.size(); i++){
			content = content+inviteId.get(i)+"&";
		}
		content = content.trim().substring(0, content.trim().length()-1);
		isfsObject.putUtfString("sms_req_content",content);
		isfsObject.putUtfString("sms_target_id",groupId);
		isfsObject.putUtfString("customerId",SmartFoxClient.getLoginUserId());
		isfsObject.putUtfString("groupid", groupId);
		isfsObject.putInt("type",MessageEntity.TYPE_INVITATION);
		smartFoxClient.doSendExtentionReq(isfsObject);
		return true;
	}
	
	/**
	 * 发送参数为数组类型请求
	 */
	public static void sendArrayRequest(int code,Collection<String> codes) {
		ISFSObject isfsObject = new SFSObject();
		isfsObject.putInt(KEY_CODE, code);
		isfsObject.putUtfStringArray(KEY_PARAME, codes);
		smartFoxClient.doSendExtentionReq(isfsObject);
	}
	
	/**
	 * 发送聊天收费
	 * @param time
	 * @param price
	 * @param chatId
	 * @param type 医生发0    客户发1
	 */
	public static void sendDoctorCharge(String time,String price,String chatId,String orid,int type){
		ISFSObject isfsObject = new SFSObject();
		isfsObject.putInt(KEY_CODE,RequestCode.CODE_CHARGE_STATE);
		isfsObject.putUtfString("money", price);
		isfsObject.putUtfString("time", time);
		isfsObject.putInt("type",type); //医生发0    客户发1
		if(orid != null)isfsObject.putUtfString("orid",orid);
		isfsObject.putUtfString("sms_target_id",chatId);
		smartFoxClient.doSendExtentionReq(isfsObject);
	}
	
	// 删除离线消息
	public static void deleteHistroyMessage(List<MessageEntity> list) {
		if(list == null || list.size() == 0)return;
		List<String> idList = new ArrayList<String>();
		for (MessageEntity messageEntity : list) {
			final String  serverid = messageEntity.getServerId();
			if(serverid != null)idList.add(serverid);
		}
		sendArrayRequest(SmartFoxClient.RequestCode.OFFLINE_DELE,idList);
	}
	
	public static void sendLogoutGroup(String grouId){
		ISFSObject isfsObject = new SFSObject();
		isfsObject.putInt(KEY_CODE,RequestCode.EXIT_GROUP_CHAT);
		isfsObject.putUtfString(KEY_PARAME,grouId);
		smartFoxClient.doSendExtentionReq(isfsObject);
	}
}
